//
//  YGNewFeatureViewCell.swift
//  sinaWeiBoGui
//
//  Created by liyonggui on 16/5/14.
//  Copyright © 2016年 liyonggui. All rights reserved.
//

import UIKit

class YGNewFeatureViewCell: UICollectionViewCell {
    
    // MARK: - 属性
    var index:Int = 0 {
        didSet {
            startButton.hidden = true
//            YGPrint(items: "\(index)")
            bkgView.image = UIImage(named: "new_feature_\(index + 1)")
        }
    }
    
    // MARK: - "开始体验" 按钮的动画事件
    func startAnimation() {
        
        startButton.hidden = false
        // 开始动画之前
        startButton.transform = CGAffineTransformMakeScale(0, 0)
        
        UIView.animateWithDuration(0.5, delay: 0, usingSpringWithDamping: 0.5, initialSpringVelocity: 5, options: UIViewAnimationOptions(rawValue: 0), animations: { () -> Void in
            
//            startButton.transform = CGAffineTransformMakeScale(1, 1)
            self.startButton.transform = CGAffineTransformIdentity
            
            }, completion: nil)
        
    }
    
    // MARK: - "开始体验" 按钮点击事件
    func startButtonClick() {
        let myAppDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
        myAppDelegate.switchController(YGMainTabBarViewController())
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        prepareUI()
    }
    
    // 设置UI
    private func prepareUI() {
        
        contentView.addSubview(bkgView)
        contentView.addSubview(startButton)
        
        // 添加约束
        bkgView.snp_makeConstraints { (make) -> Void in
            make.edges.equalTo(contentView)
        }
        
        startButton.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(contentView)
            make.bottom.equalTo(contentView).offset(-160)
        }
    }

    // MARK: - 懒加载
    /// 背景图片
    private lazy var bkgView: UIImageView = UIImageView(image: UIImage(named: "new_feature_1"))
    /// 按钮
    private lazy var startButton: UIButton = {
        let button = UIButton()
        
        // 背景图片
        button.setBackgroundImage(UIImage(named: "new_feature_finish_button_highlighted"), forState: UIControlState.Highlighted)
        button.setBackgroundImage(UIImage(named: "new_feature_finish_button"), forState: UIControlState.Normal)
        
        // 设置文字
        button.setTitle("开始体验", forState: UIControlState.Normal)
        button.setTitleColor(UIColor.whiteColor(), forState: UIControlState.Normal)
        
        button.hidden = true
        
        // 添加点击事件
        button.addTarget(self, action: "startButtonClick", forControlEvents: UIControlEvents.TouchUpInside)
        
        return button
    }()
    
}
































